/*
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2004-2007 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV50_VIDEO_DECODER)

#include <ippi.h>
#include "umc_dv50_decoder.h"
#include "umc_dv50_internal.h"

namespace UMC
{

void store_dv50_segment_8s_reference(STORE_DV_SEGMENT_INFO &StoreInfo)
{
#undef WRITE_2PIXELS
#define WRITE_2PIXELS(pointer_dst, pointer_y, pointer_u, pointer_v) \
    (pointer_dst)[0] = SaturateByte(*(pointer_y + 0) + 128);    \
    (pointer_dst)[1] = SaturateByte(*(pointer_u + 0) + 128);    \
    (pointer_dst)[2] = SaturateByte(*(pointer_y + 128) + 128);  \
    (pointer_dst)[3] = SaturateByte(*(pointer_v + 0) + 128);

    Ipp16s *lpsSrc, *lpsSrcV;
    Ipp8u *lpbDst;
    Ipp32u MacroBlock;

    for (MacroBlock = 0;MacroBlock < 5;MacroBlock += 1)
    {
        lpsSrc = (Ipp16s *) StoreInfo.m_lpsSource[MacroBlock];
        lpsSrcV = lpsSrc + 4 * 64;
        lpbDst = StoreInfo.m_lpbDestination[MacroBlock];

        // write macro block
        WRITE_2PIXELS(lpbDst + 0, lpsSrc + 0, lpsSrcV + 64, lpsSrcV + 0)
    }

} // void store_dv50_segment_8s_reference(STORE_DV_SEGMENT_INFO &StoreInfo)

void StoreDV50Segment_YUY2_8s(STORE_DV_SEGMENT_INFO &StoreInfo)
{
    // place you optimized code here
    // ...

    store_dv50_segment_8s_reference(StoreInfo);

} // void StoreDV50Segment_YUY2_8s(STORE_DV_SEGMENT_INFO &StoreInfo)

void DV50VideoDecoder::StoreDV50Segment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)
{
    STORE_DV_SEGMENT_INFO RealStoreInfo;

    // reset pointers
    InitializeStoreDV50Info(RealStoreInfo, i, k, nThreadNum);

    StoreDV50Segment_YUY2_8s(RealStoreInfo);

} // void DV50VideoDecoder::StoreDVSegment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)

} // end namespace UMC

#endif //(UMC_ENABLE_DV50_VIDEO_DECODER)
